<template>
  <div class="container">
    <div class="topsearch">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <div class="searchs">
          <el-form-item>
            <el-input
              placeholder="广告位名称"
              v-model="formInline.user"
              clearable
            >
            </el-input>
          </el-form-item>
          <el-form-item>
            <el-select
              v-model="formInline.value"
              style="width: 120px; font-size: 10px"
              placeholder="类型"
              clearable
            >
              <el-option
                v-for="item in formInline.options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="info" size="medium" @click="onSubmit"
              >查询</el-button
            >
          </el-form-item>
        </div>
      </el-form>
      <el-button type="primary" class="addBtn" @click="dialogFormVisible = true"
        >新增</el-button
      >
    </div>
    <!-- 表格 -->
    <el-table
      ref="multipleTable"
      :data="tableData"
      border
      tooltip-effect="dark"
      style="width: 100%"
      :header-cell-style="{
        background: '#FAFAFA',
        fontWeight: '900',
        color: '#606266',
      }"
      size="small"
      @selection-change="handleSelectionChange"
    >
      <el-table-column prop="date" label="广告位名称" width="200">
      </el-table-column>
      <el-table-column prop="name" label="类型" width="80"> </el-table-column>
      <el-table-column
        prop="user"
        label="长度(px)"
        width="80"
      ></el-table-column>
      <el-table-column prop="name" label="宽度(px)" width="80">
      </el-table-column>
      <el-table-column prop="name" label="是否可关闭" width="120">
      </el-table-column>
      <el-table-column prop="name" label="悬浮位置" width="120">
      </el-table-column>
      <el-table-column prop="user" label="默认显示" show-overflow-tooltip>
      </el-table-column>

      <el-table-column prop="meke" label="操作" width="250">
        <template slot-scope="scope">
          <el-button type="text" size="mini" @click="handleTableEdit(scope.row)"
            >查看</el-button
          >
          <el-button
            type="text"
            class="state0"
            size="mini"
            @click="handleTableEdit(scope.row)"
            >删除</el-button
          >
          <el-button type="text" size="mini" @click="deleteClick(scope.row)"
            >编辑</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页器 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage4"
      :page-sizes="[100, 200, 300, 400]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total="400"
    >
    </el-pagination>
    <!-- 编辑弹窗 -->
    <el-dialog
      title="广告位编辑"
      width=" 600px"
      :visible.sync="dialogFormVisible"
    >
      <el-form :model="form" size="small">
        <el-form-item label="广告位名称" :label-width="formLabelWidth">
          <el-input
            style="width: 300px"
            v-model="form.name"
            autocomplete="off"
            placeholder="请输入"
          ></el-input>
        </el-form-item>
        <el-form-item label="类型" :label-width="formLabelWidth">
          <el-select v-model="form.type" placeholder="请选择">
            <el-option
              v-for="item in form.options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="长度" :label-width="formLabelWidth">
          <el-input
            style="width: 300px"
            v-model="form.name"
            autocomplete="off"
            placeholder="请输入"
          ></el-input>
        </el-form-item>
        <el-form-item label="高度" :label-width="formLabelWidth">
          <el-input
            style="width: 300px"
            v-model="form.name"
            autocomplete="off"
            placeholder="请输入"
          ></el-input>
        </el-form-item>
        <el-form-item label="是否可关闭" :label-width="formLabelWidth">
          <el-switch
            v-model="close"
            active-color="#13ce66"
            inactive-color="#ff4949"
          >
          </el-switch>
        </el-form-item>
        <el-form-item label="位置X" :label-width="formLabelWidth">
          <el-input
            style="width: 300px"
            v-model="form.name"
            autocomplete="off"
            placeholder="请输入"
          ></el-input>
        </el-form-item>
        <el-form-item label="位置Y" :label-width="formLabelWidth">
          <el-input
            style="width: 300px"
            v-model="form.name"
            autocomplete="off"
            placeholder="请输入"
          ></el-input>
        </el-form-item>
        <el-form-item label="默认显示" :label-width="formLabelWidth">
          <el-switch
            v-model="show"
            active-color="#13ce66"
            inactive-color="#ff4949"
          >
          </el-switch>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          size="small"
          @click="dialogFormVisible = false"
          >保存</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      formInline: {
        user: "",
        value: "",
        options: [
          {
            value: "选项1",
            label: "男",
          },
          {
            value: "选项2",
            label: "女",
          },
        ],
      },
      close: true,
      show: true,
      form: {
        typy: "",

        options: [
          {
            value: "选项1",
            label: "黄金糕",
          },
          {
            value: "选项2",
            label: "双皮奶",
          },
        ],
      },
      tableData: [
        {
          date: "金源花园",
          name: "B21",
          user: "admin",
          state: "0",
          number: "13286952622",
          info: 228,
          counts: 30,
          pay: "5元/小时",
        },
        {
          date: "金源花园",
          name: "B99",
          user: "admin",
          state: "1",
          info: 128,
          counts: 60,
          number: "13286952622",
          pay: "5元/小时",
        },
      ],
      multipleSelection: [],
      currentPage4: 4,
      dialogFormVisible: false,
      form: {
        name: "",
      },
      formLabelWidth: "100px",
      src: "https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg",
    };
  },
  methods: {
    onSubmit() {
      console.log("submit!");
    },
    toggleSelection(rows) {
      if (rows) {
        rows.forEach((row) => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
    //编辑
    handleTableEdit(val) {
      console.log(val);
      this.dialogFormVisible = true;
    },
    deleteClick() {
      this.dialog = true;
    },
  },
};
</script>
<style scoped lang="less">
.container {
  padding: 10px;
}
.topsearch {
  display: flex;
  justify-content: space-between;
  align-items: center;
  .addBtn {
    margin-bottom: 22px;
  }
}
.el-pagination {
  position: absolute;
  right: 5px;
  margin-top: 15px;
}
.state0 {
  color: #fb1a07;
}
.demo-image {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}
.block {
  width: 100px;
  height: 80px;
  overflow: hidden;
  background: rgba(220, 220, 220, 0.8);
}
::v-deep .dialog .el-dialog__body {
  padding: 30px 20px 10px !important;
}
::v-deep .el-dialog__body {
  padding: 30px 90px 10px !important;
}
::v-deep .el-dialog__footer {
  text-align: center;
}
</style>
